/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Universidad de La Frontera
 * License Type: Academic
 */
package orm;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;

public class TipoConsumoDAO {
	public static TipoConsumo loadTipoConsumoByORMID(int tipocon_ID) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return loadTipoConsumoByORMID(session, tipocon_ID);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo getTipoConsumoByORMID(int tipocon_ID) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return getTipoConsumoByORMID(session, tipocon_ID);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo loadTipoConsumoByORMID(int tipocon_ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return loadTipoConsumoByORMID(session, tipocon_ID, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo getTipoConsumoByORMID(int tipocon_ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return getTipoConsumoByORMID(session, tipocon_ID, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo loadTipoConsumoByORMID(PersistentSession session, int tipocon_ID) throws PersistentException {
		try {
			return (TipoConsumo) session.load(orm.TipoConsumo.class, new Integer(tipocon_ID));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo getTipoConsumoByORMID(PersistentSession session, int tipocon_ID) throws PersistentException {
		try {
			return (TipoConsumo) session.get(orm.TipoConsumo.class, new Integer(tipocon_ID));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo loadTipoConsumoByORMID(PersistentSession session, int tipocon_ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (TipoConsumo) session.load(orm.TipoConsumo.class, new Integer(tipocon_ID), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo getTipoConsumoByORMID(PersistentSession session, int tipocon_ID, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (TipoConsumo) session.get(orm.TipoConsumo.class, new Integer(tipocon_ID), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryTipoConsumo(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return queryTipoConsumo(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryTipoConsumo(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return queryTipoConsumo(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo[] listTipoConsumoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return listTipoConsumoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo[] listTipoConsumoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return listTipoConsumoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryTipoConsumo(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.TipoConsumo as TipoConsumo");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static List queryTipoConsumo(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.TipoConsumo as TipoConsumo");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.list();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo[] listTipoConsumoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		try {
			List list = queryTipoConsumo(session, condition, orderBy);
			return (TipoConsumo[]) list.toArray(new TipoConsumo[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo[] listTipoConsumoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			List list = queryTipoConsumo(session, condition, orderBy, lockMode);
			return (TipoConsumo[]) list.toArray(new TipoConsumo[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo loadTipoConsumoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return loadTipoConsumoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo loadTipoConsumoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return loadTipoConsumoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo loadTipoConsumoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		TipoConsumo[] tipoConsumos = listTipoConsumoByQuery(session, condition, orderBy);
		if (tipoConsumos != null && tipoConsumos.length > 0)
			return tipoConsumos[0];
		else
			return null;
	}
	
	public static TipoConsumo loadTipoConsumoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		TipoConsumo[] tipoConsumos = listTipoConsumoByQuery(session, condition, orderBy, lockMode);
		if (tipoConsumos != null && tipoConsumos.length > 0)
			return tipoConsumos[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTipoConsumoByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return iterateTipoConsumoByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTipoConsumoByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.TrabajoAplicado1PersistentManager.instance().getSession();
			return iterateTipoConsumoByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTipoConsumoByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.TipoConsumo as TipoConsumo");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTipoConsumoByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.TipoConsumo as TipoConsumo");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo createTipoConsumo() {
		return new orm.TipoConsumo();
	}
	
	public static boolean save(orm.TipoConsumo tipoConsumo) throws PersistentException {
		try {
			orm.TrabajoAplicado1PersistentManager.instance().saveObject(tipoConsumo);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean delete(orm.TipoConsumo tipoConsumo) throws PersistentException {
		try {
			orm.TrabajoAplicado1PersistentManager.instance().deleteObject(tipoConsumo);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.TipoConsumo tipoConsumo)throws PersistentException {
		try {
			orm.Consumo[] lConsumos = tipoConsumo.consumo.toArray();
			for(int i = 0; i < lConsumos.length; i++) {
				lConsumos[i].setTipoConsumotipocon(null);
			}
			return delete(tipoConsumo);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean deleteAndDissociate(orm.TipoConsumo tipoConsumo, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Consumo[] lConsumos = tipoConsumo.consumo.toArray();
			for(int i = 0; i < lConsumos.length; i++) {
				lConsumos[i].setTipoConsumotipocon(null);
			}
			try {
				session.delete(tipoConsumo);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean refresh(orm.TipoConsumo tipoConsumo) throws PersistentException {
		try {
			orm.TrabajoAplicado1PersistentManager.instance().getSession().refresh(tipoConsumo);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static boolean evict(orm.TipoConsumo tipoConsumo) throws PersistentException {
		try {
			orm.TrabajoAplicado1PersistentManager.instance().getSession().evict(tipoConsumo);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static TipoConsumo loadTipoConsumoByCriteria(TipoConsumoCriteria tipoConsumoCriteria) {
		TipoConsumo[] tipoConsumos = listTipoConsumoByCriteria(tipoConsumoCriteria);
		if(tipoConsumos == null || tipoConsumos.length == 0) {
			return null;
		}
		return tipoConsumos[0];
	}
	
	public static TipoConsumo[] listTipoConsumoByCriteria(TipoConsumoCriteria tipoConsumoCriteria) {
		return tipoConsumoCriteria.listTipoConsumo();
	}
}
